from rest_framework import serializers
from task.models import TaskLog


class TaskLogSerializer(serializers.ModelSerializer):
    def to_representation(self, instance):
        data = super().to_representation(instance)
        data['connection'] = {
            'id': instance.connection_id,
            'partner': {
                'id': instance.connection.partner.id,
                'name': instance.connection.partner.name
            }
        }
        return data

    class Meta:
        model = TaskLog
        fields = '__all__'
